import Page from '../../common/page';
// Page({
// });
var p = 1;
var url = "http://localhost:8888/newcoder";
var getList = function (that){

      wx.request({
        url: url,
        data: {
          pageSize: 10,
          pageNo: p  
        },
        method: 'GET',
        success: function (res) {
          // success
          console.log(res.data)
          var l = that.data.newcodes;
          for (var i = 0; i < res.data.content.length; i++) {
            l.push(res.data.content[i]);
          } 
          that.setData({
            newcodes: l
          })
          p++; 
        },
        fail: function () {
          // fail
        },
        complete: function () {
          // complete
        }
      })
}

Page({
    data: {
      text: "This is page data.",
      newcodes:[],
      htnlText:""
    },
    onLoad() {
      var _that = this;
      var that = this;
      getList(that); 
        // wx.request({
        //     url: 'http://localhost:8888/newcoder',
        //     header: {
        //       'content-type': 'application/json' // 默认值
        //     },
        //     success (res) {
        //       _that.setData({
        //         newcodes:res.data
        //       });
              
        //     }
        //   })
          
    },
    goDetail:function(item){
        var data = item.currentTarget.dataset.item;
        console.log(data.id)
        wx.navigateTo({
        url: '../newcoderdetail/index?id='+data.id
      })
    },
    onPullDownRefresh: function () {
      //下拉  
      console.log("下拉");
      p = 1;
      var that = this
      that.setData({
        newcodes: [],
      });

      getList(that)
    },
    onReachBottom: function () {
      //上拉  
      console.log("上拉")
      var that = this
      getList(that)
    }
  })
  